#include <iostream>
using namespace std;

int integerReplacement(int n)
{
    int temp = n;
    int count = 0;
    while (temp != 1)
    {
        if (temp & 3 == 3 && temp != 3)
            count++;
        else if (temp & 1 == 1)
            count--;
        else
            temp >>= 1;
        count++;
    }
    return count;
}